主题
连接服务器 - TcpClientConnect
函数简介
连接到服务器(异步操作,结果通过回调通知)。
接口名称
TcpClientConnectDLL调用
c
int32_t TcpClientConnect(int64_t instance, int64_t client_handle, const char* host, int32_t port);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| client_handle | 长整数型 | 客户端句柄 |
| host | 字符串 | 主机名或IP地址 |
| port | 整数型 | 端口号 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long client = ola.TcpClientCreate(nullptr, 0, 0);
int ret = ola.TcpClientConnect(client, "127.0.0.1", 9000);csharp
using OLAPlug;
var ola = new OLAPlugServer();
long client = ola.TcpClientCreate(nullptr, 0, 0);
int ret = ola.TcpClientConnect(client, "127.0.0.1", 9000);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
client = ola.TcpClientCreate(nullptr, 0, 0)
ret = ola.TcpClientConnect(client, "127.0.0.1", 9000)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
long client = ola.TcpClientCreate(nullptr, 0, 0);
int ret = ola.TcpClientConnect(client, "127.0.0.1", 9000);cpp
var ola = com("OlaPlug.OlaSoft")
var client = ola.TcpClientCreate(nullptr, 0, 0)
var ret = ola.TcpClientConnect(client, "127.0.0.1", 9000)vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
client = ola.TcpClientCreate(nullptr, 0, 0)
ret = ola.TcpClientConnect(client, "127.0.0.1", 9000)text
.局部变量 ola, OLAPlug
ola.创建 ()
client = ola.TcpClientCreate(nullptr, 0, 0)
ret = ola.TcpClientConnect(client, “127.0.0.1“, 9000)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var client = ola.TcpClientCreate(nullptr, 0, 0);
var ret = ola.TcpClientConnect(client, "127.0.0.1", 9000);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 client = ola.TcpClientCreate(nullptr, 0, 0)
整数 ret = ola.TcpClientConnect(client, "127.0.0.1", 9000)cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long client = ola.TcpClientCreate(nullptr, 0, 0);
int ret = ola.TcpClientConnect(client, "127.0.0.1", 9000);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long client = TcpClientCreate(instance, nullptr, 0, 0);
TcpClientConnect(instance, client, "127.0.0.1", 9000);csharp
long instance = CreateCOLAPlugInterFace();
long client = TcpClientCreate(instance, nullptr, 0, 0);
TcpClientConnect(instance, client, "127.0.0.1", 9000);python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
client = TcpClientCreate(instance, nullptr, 0, 0)
TcpClientConnect(instance, client, "127.0.0.1", 9000)返回值
整数型,1 成功(开始连接,最终结果通过回调通知),0 失败。
注意事项
- 这是异步操作,函数立即返回
- 连接结果通过回调函数通知(event_type=0成功,event_type=1失败)
- 支持IPv4和IPv6地址
- 支持域名解析
- 如果已经连接,再次调用会失败
